package com.czl.module_storehouse.mvp.model;

import com.czl.base.data.net.RetrofitClient;
import com.czl.module_base.bean.FileServiceResult;
import com.czl.module_base.http.HttpResponse;
import com.czl.module_storehouse.api.ApiService;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.Observable;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;

/**
 * @author by xubin,
 * @date on 2022/2/25.
 * PS: Not easy to write code, please indicate.
 */
public class UploadModel extends BasicDataModel {
    public static String SERVER_BASE_UPLOAD_URL = RetrofitClient.baseUrl + "file/upload";

    /**
     * 上传file
     *
     * @param file
     * @return
     */
    public Observable<HttpResponse<FileServiceResult>> uploadFile(File file) {
        return null;
    }

    /**
     * 上传file
     *
     * @param file
     * @param showLoading
     * @return
     */
    public Observable<FileServiceResult> uploadFile(File file, boolean showLoading) {
        return null;
    }

    /**
     * 上传多个file
     *
     * @param files
     * @return
     */
    public Observable<List<String>> uploadFile(List<File> files) {
        return null;
    }

    /**
     * 上传多个path
     *
     * @param paths
     * @return
     */
    public Observable<List<String>> uploadPaths(List<String> paths) {
        return null;
    }

    /**
     * 上传单个path
     *
     * @param path
     * @return
     */
    public Observable<HttpResponse<FileServiceResult>> uploadPath(String path) {
        File file = new File(path);
        Map<String, String> map = new HashMap<>(0);
        map.put("bucketName", "szchd");
        map.put("folderName", "assets");
        RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), file);
        MultipartBody.Part body = MultipartBody.Part.createFormData("file", file.getName(), requestFile);
        return RetrofitClient.getInstance().create(ApiService.class)
                .uploadFile(map, body);
    }

    /**
     * 下载文件
     *
     * @param imageUrl
     * @return
     */
    public Observable<File> downloadFile(String imageUrl) {
        return null;
    }
}
